var countdown=60;
function settime(obj) {
    if (countdown == 0) {
        obj.removeAttribute("disabled");
        obj.value="免费获取验证码";
        countdown = 60;
        return;
    } else {
        obj.setAttribute("disabled", true);
        obj.value="重新发送(" + countdown + ")";
        countdown--;
    }
    setTimeout(function() {
            settime(obj) }
        ,1000)
}

//发送短信验证
function get_validate_code(obj) {
    var mobile = $("input[name='username']").val();
    if (mobile.length != 11)
    {
        alert("手机号格式不正确!");
        return;
    }

    $.ajax({
        url:"registerWeb/sendValidMsgWeb.json",
        type:'POST',
        dataType:"json",
        data:{
            'mobile':mobile
        },
        success:function(result){
        }
    });

    settime(obj);
}

//提交注册
function loginRegisterSubmit(){
    if($("input[name='password']").val() != $("input[name='isPassword']").val()){
        alert("两次密码输入不正确");
    }else if($('input[name="marry"]:checked').size() == 0){
        alert("请同意注册条款");
    }else if($("#s_county option:selected").val() == ''){
        alert("请选择省市区");
    }else {
        $.ajax({
            url: "registerWeb/bizTenantsMoreWeb.json",
            type: 'POST',
            dataType: "json",
            data: $("#loginRegisterForm").serialize(),
            success: function (result) {
                alert(result.msg);
                if (result.isOK == "OK") {
                    window.location.href = "/";
                }
            },
            error: function () {
                alert("请求失败");
            }
        });
    }
}

//根据市查询所有区
var countyFunction = function(city){
    $.ajax({
        url:"cityWeb/findAllAreaByCity.json",
        type:'POST',
        dataType:"json",
        data:{
            city:city
        },
        success:function(result){
            var tem = "<option value=''>区域</option>";
            $.each( result.byOpenCityList, function(index, content){
                tem += "<option value='"+content.area+"'>"+content.area+"</option>";
            });
            $("#s_county").empty();
            $("#s_county").append(tem);
            $(".loginBox .loginDiv ul li .loginSelect1:nth-child(3)").css({'margin-right':'0','float':'right','position':'absolute','right':'0','top':'0'});
        }
    });
}

//根据省份查询所有市
var cityFunction = function(province){
    $.ajax({
        url:"cityWeb/findAllCityByProvince.json",
        type:'POST',
        dataType:"json",
        data:{
            province:province
        },
        success:function(result){
            var tem = "<option value=''>城市</option>";
            $.each( result.byOpenCityList, function(index, content){
                tem += "<option value='"+content.city+"'>"+content.city+"</option>";
            });
            $("#s_city").empty();
            $("#s_city").append(tem);
            $(".loginBox .loginDiv ul li .loginSelect1:nth-child(3)").css({'margin-right':'0','float':'right','position':'absolute','right':'0','top':'0'});
        }
    });
}

//获取开通省份
var provinceFunction = function(){
    $.ajax({
        url:"cityWeb/findAllProvince.json",
        type:'GET',
        dataType:"json",
        success:function(result){
            var tem = "<option value=''>省份</option>";
            $.each( result.byOpenCityList, function(index, content){
                tem += "<option value='"+content.province+"'>"+content.province+"</option>";
            });
            $("#s_province").empty();
            $("#s_province").append(tem);
            $(".loginBox .loginDiv ul li .loginSelect1:nth-child(3)").css({'margin-right':'0','float':'right','position':'absolute','right':'0','top':'0'});
        }
    });
}();

function provinceChange(){
    var options=$("#s_province option:selected");
    cityFunction(options.val());
}

function cityChange () {
    var options=$("#s_city option:selected");
    countyFunction(options.val());
}